package chapter21;

import java.util.ArrayList;
import java.util.List;

public class Chapter21Main {

    public static void main(String[] args) {
        List<Connection.Graph.Node> V = new ArrayList<>();
        Connection.Graph.Node a = new Connection.Graph.Node("a", 0);
        Connection.Graph.Node b = new Connection.Graph.Node("b", 1);
        Connection.Graph.Node c = new Connection.Graph.Node("c", 2);
        Connection.Graph.Node d = new Connection.Graph.Node("d", 3);
        Connection.Graph.Node e = new Connection.Graph.Node("e", 4);
        Connection.Graph.Node f = new Connection.Graph.Node("f", 5);
        Connection.Graph.Node g = new Connection.Graph.Node("g", 6);
        Connection.Graph.Node h = new Connection.Graph.Node("h", 7);
        Connection.Graph.Node i = new Connection.Graph.Node("i", 8);
        Connection.Graph.Node j = new Connection.Graph.Node("j", 9);
        V.add(a);
        V.add(b);
        V.add(c);
        V.add(d);
        V.add(e);
        V.add(f);
        V.add(g);
        V.add(h);
        V.add(i);
        V.add(j);

        Connection.Graph graph = new Connection.Graph();
        graph.V = V;
        graph.table = new Connection.Graph.Node[10];
        graph.table[0] = new Connection.Graph.Node("a", 0);
        graph.table[0].next = new Connection.Graph.Node("b", 1);
        graph.table[0].next.next = new Connection.Graph.Node("c", 2);
        graph.table[1] = new Connection.Graph.Node("b", 1);
        graph.table[1].next = new Connection.Graph.Node("c", 2);
        graph.table[1].next.next = new Connection.Graph.Node("d", 3);
        graph.table[2] = new Connection.Graph.Node("c", 2);
        graph.table[3] = new Connection.Graph.Node("d", 3);
        graph.table[4] = new Connection.Graph.Node("e", 4);
        graph.table[4].next = new Connection.Graph.Node("f", 5);
        graph.table[4].next.next = new Connection.Graph.Node("g", 6);
        graph.table[5] = new Connection.Graph.Node("f", 5);
        graph.table[6] = new Connection.Graph.Node("g", 6);
        graph.table[7] = new Connection.Graph.Node("h", 7);
        graph.table[7].next = new Connection.Graph.Node("i", 8);
        graph.table[8] = new Connection.Graph.Node("i", 8);
        graph.table[9] = new Connection.Graph.Node("j", 9);

        List<List<Connection.Graph.Node>> rs = Connection.connected(graph);
        System.out.println(rs);


        Link.Node aa = new Link.Node("a");
        Link.Node bb = new Link.Node("b");
        Link.Node cc = new Link.Node("c");
        Link.Node dd = new Link.Node("d");
        Link.Node ee = new Link.Node("e");
        Link.Node ff = new Link.Node("f");
        Link.Node gg = new Link.Node("g");
        Link.Node hh = new Link.Node("h");
        Link.markSet(aa);
        Link.markSet(bb);
        Link.markSet(cc);
        Link.markSet(dd);
        Link.markSet(ee);
        Link.markSet(ff);
        Link.markSet(gg);
        Link.markSet(hh);

        Link.union(bb, hh);
        Link.union(hh, cc);
        Link.union(ee, cc);
        Link.union(gg, dd);
        Link.union(dd, ff);
        Link.union(cc, ff);

    }

}
